Skip to content

[python] Enforce global limit for Torch streaming reads - #8977

Closed
XiaoHongbo-Hope wants to merge 1 commit into
apache:masterfrom
XiaoHongbo-Hope:codex/fix-torch-global-limit
Closed

XiaoHongbo-Hope wants to merge 1 commit into
apache:masterfrom
XiaoHongbo-Hope:codex/fix-torch-global-limit

Conversation

@XiaoHongbo-Hope

Copy link
Copy Markdown
Contributor

Purpose

TableRead.to_iterator applies its limit within one iterator. A streaming Torch dataset creates multiple iterators across DataLoader workers, split-prefetch threads, and shuffled split readers, so each iterator could consume the full limit independently. For example, two four-row splits with LIMIT 5 returned eight rows with two DataLoader workers.

This change adds a row quota shared by all worker processes and prefetch threads. A reader reserves quota before materializing its next row and returns unused reservations when an iterator is exhausted. The quota resets after all workers finish an iteration, including with persistent workers. Split assignment, worker concurrency, and prefetch concurrency remain enabled.

This bug predates and is independent of #8808, so the fix is submitted separately.

Tests

  • python3.11 -m pytest -q pypaimon/tests/torch_read_test.py (19 passed, 2 subtests passed)
  • python3.11 -m flake8 --config=dev/cfg.ini pypaimon/read/datasource/torch_dataset.py pypaimon/tests/torch_read_test.py
  • Python 3.6 py_compile for the changed Python files
  • git diff --check

The regression coverage includes fork and spawn DataLoader workers, concurrent split prefetch, persistent-worker iteration reset, and shuffled streaming reads.

@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as draft August 1, 2026 08:21
@XiaoHongbo-Hope

Copy link
Copy Markdown
Contributor Author

Closing this draft because the Torch streaming global-limit issue predates and is independent of #8808. The cross-process quota implementation adds substantial complexity for a narrowly scoped behavior; we can revisit it separately if global LIMIT semantics are required for multi-worker Torch streaming reads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant